<?php
class BindAcfun {
	private $message = "";
	private $cp = null;
	function BindAcfun() {
		$this->cp = new ClusterParam();
	}

	public function run() {
		//$_SESSION['NOWMODE']=isset($_SESSION['NOWMODE'])?$_SESSION['NOWMODE']:"bindAcfun";
//		if($_POST[Sender]!="261589289")
//		return;
		$_SESSION['bd']['is_select_type'] = isset ($_SESSION['bd']['is_select_type']) ? 1 : 0;
		
		if ($_SESSION['bd']['is_select_type'] == 0){
			$this->message = "开始绑定相关账号了哦，请选择需要绑定的账号类型 \n" .
					"1.绑定acfun 账号\n" .
					"2.绑定哔哩哔哩账号\n" .
					"3.绑定百度账号\n".
					"-q 退出绑定\n".
					"相关帮助：http://tieba.baidu.com/p/2676680163 ";
					return;
		}
		if($_SESSION['bd']['is_select_type']==1 && !isset($_SESSION['bd']['type'])) {
			if(trim($_POST[Message]==1)) {
				$_SESSION['bd']['type']="ac";
				$_SESSION['bd']['name']="acfun";
			} else if(trim($_POST[Message]==2)) {
				$_SESSION['bd']['type']="av";
				$_SESSION['bd']['name']="哔哩哔哩";
			}else if(trim($_POST[Message]==3)) {
				$_SESSION['bd']['type']="du";
				$_SESSION['bd']['name']="百度";
			}else if(trim($_POST[Message]=="-q")) {
				$this->__q(false);
			} else {
				
				$this->message = "您选择的账号类型不存在~";
				return;
			}
		}
		$_SESSION['bd']['is_first_enter'] = isset ($_SESSION['bd']['is_first_enter']) ? 1 : 0;
		if ($_SESSION['bd']['is_first_enter'] == 0 && isset($_SESSION['bd']['type'])) {
			$this->message = "开始绑定【".$_SESSION['bd']['name']."】账号了哦，信任索妮娅的话就绑定吧。。 \n" .
			"设置账号请输入 -u 账号\n" .
			"设置密码请输入 -p 密码\n" .
			"解除绑定请输入 -r\n" ;
			if($_SESSION['bd']['type']=="ac") { 
				$this->message.= "回复后缀请输入 -e 添加或不添加\n" ;
			}
			$this->message.= "查看当前设置： -v\n" .
			"更新与设置一样操作\n" .
			"返回上一层输入 -b\n".
			"退出请输入 -q\n";
			return;
		}
		if (preg_match('/^-(\S+)\s*(.*)$/is', trim($_POST[Message]), $m)) {
			$funName = "__" . $m[1];
			
				if(method_exists($this,$funName))
				{
					$this-> $funName($m);
				}else{
					$this->message = "咦、说什么呢╮(╯▽╰)╭";
				}
				
			
		} else {
					$this->message = "貌似，命令什么的格式不对啊- -";
		}

	}

	private function __q($m) {
		if($_POST[Event]=="ReceiveNormalIM")
			unset ($_SESSION['NOWMODE']);
		else
			unset ($_SESSION['QUN_MODE']);
		unset ($_SESSION['bd']);
		$this->message = "退出绑定模式了哦，多多和我说话吧，喵~！";
	}

	private function __p($m) {
		$type = $_SESSION['bd']['type'];
		if (trim($m[2]) == "") {
			$this->message = "密码什么的好像还没写呢。。仔细看下啦";
		} else {
			$this->message =$this->cp->saveMyParamValue($type."password", trim($m[2]));
		}
	}

	private function __u($m) {
		$type = $_SESSION['bd']['type'];
		if ($m[2] == "") {
			$this->message = "用户名什么的好像没写呢。。仔细看下啦";
		} else {
			$this->message =$this->cp->saveMyParamValue($type."username", trim($m[2]));

		}
	}
	private function __e($m) {
		 if(trim($m[2])==""||!(trim($m[2])=="添加"||trim($m[2])=="不添加")) {
				 	   $this->message = "你到底是添加还是不添加啊。。。。";
				   }else{
				 	  $this->message = $this->cp->saveMyParamValue("ac_is_add_e",trim($m[2]));
				   }
	}

	private function __r($m) {
		$type = $_SESSION['bd']['type'];
		@ DB :: Query("delete from  td_my_param  where `key` in ('".$type."username','".$type."password')  and qq='{$post[Sender]}'");
		$this->message = "解除成功";
	}

	private function __v($m) {
		$type = $_SESSION['bd']['type'];
		$password = $this->cp->getMyParamValue($type."password") ? $this->cp->getMyParamValue($type."password") : " 还未配置密码";
		if($_POST[Event]!="ReceiveNormalIM") {
			$password = "********";
		}
		$this->message = "当前账号：" . ($this->cp->getMyParamValue($type."username") ? $this->cp->getMyParamValue($type."username") : " 还未配置账号") . "\n" .
		"当前密码：" . ($password) . "\n" ;
		if($_SESSION['bd']['type']=="ac")
		$this->message.="是否后缀：" . ($this->cp->getMyParamValue("ac_is_add_e") == "不添加" ? "回复内容不加后缀" : " 回复内容添加后缀");

	}
	
	private function __b($m) {
		unset ($_SESSION['bd']['type']);
		unset ($_SESSION['bd']['name']);
		unset ($_SESSION['bd']['is_first_enter']);
		$this->message = "开始绑定相关账号了哦，请选择需要绑定的账号类型 \n" .
					"1.绑定acfun 账号\n" .
					"2.绑定哔哩哔哩账号\n" .
					"3.绑定百度账号".
					"-q 退出绑定";;
	}
	
	private function __get($property_name) {
		return $this-> $property_name;
	}

	private function __set($property_name, $value) {
		$this->$property_name = $value;
	}
}
?>